package com.hengyuan.aidog.service.impl;

import com.hengyuan.aidog.dao.UserMapper;
import com.hengyuan.aidog.model.User;
import com.hengyuan.aidog.result.Result;
import com.hengyuan.aidog.result.ResultUtil;
import com.hengyuan.aidog.service.UserService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    UserMapper userMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Result loginUser(User user) {
        User selectUser = userMapper.selectUser(user);
        if(Strings.isEmpty(selectUser.getUnionid())){
            userMapper.insertUser(user);
        }else {
            userMapper.updateUser(user);
        }
        return ResultUtil.success(user);
    }
}
